﻿Imports Microsoft.Xna.Framework.Graphics
Imports Runa.Resources.ResourceManager
Imports Runa.Core.Services
Imports Runa.Foundation.Diagnostics
Imports Runa.Graphics.Effects
Imports Runa.UI.Controls
Imports Runa.Common.Helper

#If WINDOWS Then
Imports System.Drawing
#End If

Partial Public Class GameRender
    Implements IGameParameterService

    Public Property Name() As String
    Public Property Author() As String
    Public Property WindowHeight() As Integer
    Public Property WindowWidth() As Integer
    Public Property GameContentRoot() As String

    Public Property NativeContent() As ContentManager

    Public Property LoadProgress() As Integer = 0 Implements IGameParameterService.LoadProgress
    Public Property SpriteBatchs() As New Dictionary(Of String, SpriteBatch) Implements IGameParameterService.SpriteBatchs
    Public Property Fonts() As New Dictionary(Of String, FontObject) Implements IGameParameterService.Fonts
    Public Property Textures() As New Dictionary(Of String, Texture2DObject) Implements IGameParameterService.Textures
    Public Property Audios() As New Dictionary(Of String, AudioObject) Implements IGameParameterService.Audios
    Public Property Effects() As New Dictionary(Of String, EffectBase) Implements IGameParameterService.Effects
    Public Property Pages() As New Dictionary(Of String, Page)

    Public Property LastScreenShot() As RenderTarget2D Implements IGameParameterService.LastScreenShot

    Public Property Fps() As Long Implements IGameParameterService.Fps
        Get
            Return Me.TargetElapsedTime.Ticks
        End Get
        Set(value As Long)
            Me.TargetElapsedTime = TimeSpan.FromTicks(value)
        End Set
    End Property

    Public Property GPUAccelerationEnabled() As Boolean Implements IGameParameterService.GPUAccelerationEnabled
        Get
            Return Me.m_GPUAccelerationEnabled
        End Get
        Set(value As Boolean)
            If value = True Then
                Try
                    Me.Graphics.GraphicsProfile = GraphicsProfile.HiDef
                    Me.m_GPUAccelerationEnabled = True
                Catch ex As Exception
                    Me.m_GPUAccelerationEnabled = False
                End Try
            Else
                Me.m_GPUAccelerationEnabled = value
                Me.Graphics.GraphicsProfile = GraphicsProfile.Reach
            End If
        End Set
    End Property

    Public Property GameTracer() As Tracer Implements IGameParameterService.GameTracer

    Public ReadOnly Property IsHiDefSupported() As Boolean Implements IGameParameterService.IsHiDefSupported
        Get
            For Each adapter In GraphicsAdapter.Adapters
                If adapter.IsProfileSupported(GraphicsProfile.HiDef) = True Then
                    Return True
                End If
            Next
            Return False
        End Get
    End Property

    Public Property Icon() As Bitmap
        Get
            Return Me.m_icon
        End Get
        Set(value As Bitmap)
            Me.m_icon = value
            ChangeWindowIcon(Me.Window.Handle, Me.m_icon)
        End Set
    End Property

    Public Sub BeginTakeScreenShot() Implements IGameParameterService.BeginTakeScreenShot
        Me.m_screenShotGotton = True
    End Sub

    Public Sub EndTakeScreenShot() Implements IGameParameterService.EndTakeScreenShot
        Me.m_screenShotGotton = False
        Me.GraphicsDevice.SetRenderTarget(Nothing)
    End Sub

End Class